<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__STATIC__/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/css/public.css" media="all">
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">





            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>



        </div>
    </div>
    <script src="__STATIC__/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;

            table.render({
                elem: '#currentTableId',
                url: "{:url('index/MeritPayDistribute/getMeritPayDistribute')}",
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [[
                    { type: "checkbox", width: 50 },
                    { field: 'id', width: 100, title: 'ID', sort: true },
                    { field: 'company', width: 200, title: '单位' },
                    { field: 'over_teaching_workload', width: 250, title: '超教学工作量' },
                    { field: 'over_management_workload', width: 250, title: '超管理工作量' },
                    { field: 'special_performance_award', width: 250, title: '专项业绩奖励' },

                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: true,
                skin: 'line'
            });
            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                //执行搜索重载
                table.reload('currentTableId', {
                    page: {
                        curr: 1
                    }
                    , where: {
                        value: $('#value').val(),
                        modules: $('#modules').val()
                    }
                }, 'data');

                return false;
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                if (obj.event === 'add') {  // 监听添加操作
                    var index = layer.open({
                        title: '添加窗口',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['90%', '90%'],
                        content: "{:url('index/LederIncome/add')}",
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                } else if (obj.event === 'delete') {  // 监听删除操作
                    layer.confirm('真的删除这些吗', function (index) {
                        var checkStatus = table.checkStatus('currentTableId')
                            , data = checkStatus.data;
                        var ids = [];
                        for (var i = 0; i < data.length; i++) {
                            ids.push(checkStatus.data[i].user_id)
                        }
                        $.ajax({
                            data: { "id": ids },
                            url: "{:url('index/LederIncome/removeselected')}",
                            type: 'post',
                            success: function (data) {
                                if (data.code == 1) {
                                    layer.msg(data.msg);
                                } else {
                                    layer.msg(data.msg);
                                }
                            }
                        });
                        //执行搜索重载
                        table.reload('currentTableId', {
                            page: {
                                curr: 1
                            }
                        }, 'data');
                        layer.close(index);
                    });
                }
            });

            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                console.log(obj)
            });
            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {
                    var index = layer.open({
                        title: '编辑窗口',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: "{:url('index/LederIncome/edit')}?id=" + data.user_id,
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    return false;
                } else if (obj.event === 'delete') {
                    layer.confirm('真的删除行么', function (index) {
                        $.post("remove", "id=" + data.user_id, function (data) {
                            if (data.code == 1) {
                                layer.msg(data.msg);
                            } else {
                                layer.msg(data.msg);
                            }
                        });
                        obj.del();
                        layer.close(index);
                    });
                }
            });

        });
    </script>

</body>

</html>